package lambda;

import java.util.Random;
import java.util.function.Function;

/**
 * function接口生成随机的定长的字符串
 */
public class FunctionSample {
    public static void main(String[] args) {
        Function<Integer,String> randomStringFunction =l-> {
            String chars = "WERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0132456789";
            StringBuffer S = new StringBuffer();
            Random r = new Random();
            for (int i = 0; i < l; i++) {
                int index = r.nextInt(chars.length());
                S.append(chars.charAt(index));
            }
            return S.toString();
        };
        System.out.println(randomStringFunction.apply(16));

    }
}
